<?php
/**
 * Block
 * 
 * PHP4 Compatibility
 *   - Extending Object makes __construct() the constructor.
 * 
 * @package default
 * @author Daryl Koopersmith
 **/

class Block extends Object {
	var $name;
	var $class;
	var $id;
	
	/**
	 * TODO: Create a hook for before and after the run function is run.
	 */
	function __construct($name, $class) {
		global $template;
		if (empty($template))
			$template = 'index';
			//$template = nspc_get_template();
			
		$this->name = $name;
		$this->class = $class;
		$this->id = $this->class .'_'. $this->name;
	}
	
	function get_action_slug($view = NULL) {
		global $template;
		
		if (empty($view))
			$view = $template;
		//	$view = current($template);
		if ('index' == $view)
			return 'nspc_' . $this->class . '_' . $this->name;
		else
			return 'nspc_' . $view . '_' . $this->class . '_' . $this->name;
	}
	
	/**
	 * Calls the hooks and generates the output.
	 *
	 * @author Daryl Koopersmith
	 */
	function run() {
		global $template;
		//echo('template: ' . $template);
		//reset($template);
		$slug = $this->get_action_slug();
		
		//echo('running action: ' . $slug);
		
		do_action( $slug . '_before' );
		
		//while ( ! has_action($slug) ) {
		//	next($template);
		//	$slug = $this->get_action_slug();
		//}
		do_action( $slug );
		
		//reset($template);
		do_action( $this->get_action_slug() . '_after' );
	}
}

?>